package adapter;

import java.util.ArrayList;
import java.util.List;

import unit.Ambulance;
import unit.FireTruck;
import unit.PoliceCar;
import unit.Unit;

import emergency.Emergency;
import emergency.State;

import be.kuleuven.cs.swop.api.EmergencyState;
import be.kuleuven.cs.swop.api.ILocation;
import be.kuleuven.cs.swop.api.ITime;
import be.kuleuven.cs.swop.api.IUnit;
import be.kuleuven.cs.swop.api.Severity;

public class AEmergency implements be.kuleuven.cs.swop.api.IEmergency, be.kuleuven.cs.swop.api.IEvent {
	
	private Emergency em;

	public AEmergency(Emergency em){
		this.em = em;
	}
	
	@Override
	public List<IUnit> getAssignedUnits() {
		List<IUnit> units = new ArrayList<IUnit>();
		for(Unit u : em.getUnits()){
			if(u instanceof FireTruck)
				units.add(new AFireTruckView((FireTruck)u));
			else if(u instanceof Ambulance)
				units.add(new AAmbulanceView((Ambulance)u));
			else if(u instanceof PoliceCar)
				units.add(new APoliceCarView((PoliceCar)u));
		}
			
		return units;
	}

	public Emergency getEmergency(){
		return em;
	}

	@Override
	public ILocation getLocation() {
		return new ALocation(em.getLocation());
	}
	
	@Override
	public Severity getSeverity() {
		if(em.getSeverity() == emergency.Severity.BENIGN)
			return Severity.BENIGN;
		else if(em.getSeverity() == emergency.Severity.NORMAL)
			return Severity.NORMAL;
		else if(em.getSeverity() == emergency.Severity.SERIOUS)
			return Severity.SERIOUS;
		else if(em.getSeverity() == emergency.Severity.URGENT)
			return Severity.URGENT;
		else 
			return Severity.BENIGN;
	}

	@Override
	public EmergencyState getState() {
		State emState = em.getState();
		if(emState.toString().equalsIgnoreCase("statecancelled"))
			return EmergencyState.CANCELLED;
		else if (emState.toString().equalsIgnoreCase("statecompleted"))
			return EmergencyState.COMPLETED;
		else if (emState.toString().equalsIgnoreCase("stateinprogress"))
			return EmergencyState.RESPONDED;
		else if (emState.toString().equalsIgnoreCase("staterecorded"))
			return EmergencyState.UNHANDLED;
		else return EmergencyState.ANY;
	}

	@Override
	public ITime getTime() {
		return new ATime(em.getStartTimeHours(),em.getStartTimeMinutes());
	}
	
	@Override
	public boolean isPartOfDisaster() {
		return em.getDisaster()!=null;
	}

}
